package training.project.app.repository.impl;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import training.project.app.domain.Client;
import training.project.app.repository.ClientDao;
import training.project.app.repository.base.AbstractHibernateDao;

@Repository
@Transactional
public class ClientRepository extends AbstractHibernateDao<Client, Integer>
		implements ClientDao
	{
		@Override
		public Client findById(Integer clientId)
			{
				
				Criteria cr = getSession().createCriteria(Client.class,
						"client").add(Restrictions.eq("id", clientId));
				
				return (Client) cr.uniqueResult();
			}

		public Client findByCredentials(String login, String password)
			{
				Criteria cr = getSession()
						.createCriteria(Client.class, "client")
						.add(Restrictions.eq("login", login))
						.add(Restrictions.eq("password", password));
				return (Client) cr.uniqueResult();
			}
	}
